package com.example.im.app.service.impl;

import com.example.im.app.service.WebSocketMessageService;
import com.example.im.infra.executor.send.SendExecutorFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author PC
 */
@Service
public class WebSocketMessageServiceImpl implements WebSocketMessageService {

    private final static Logger logger = LoggerFactory.getLogger(WebSocketMessageServiceImpl.class);

    private SendExecutorFactory sendExecutorFactory;

    @Autowired
    public void setSendExecutorFactory(SendExecutorFactory sendExecutorFactory) {
        this.sendExecutorFactory = sendExecutorFactory;
    }

    @Override
    public void sendMessage(String sendUserName, String message) {
        logger.debug(String.format("%s send message: %s", sendUserName, message));
        sendExecutorFactory.onMessage(sendUserName, message);
    }
}
